#pragma once

#include <iostream>
#include <string>
#include <memory>
#include <ctime>
#include <unordered_map>

class Session {
    public:
        using ptr = std::shared_ptr<Session>;
        Session(const std::string &username, const std::string &status) :_username(username), _status(status){
            _create_time = time(nullptr);
        }
        ~Session() {}
    public:
        std::string _username;
        std::string _status;
        uint64_t _create_time; 
        uint64_t _time_out; 
        std::string vip; 
        int active; 
        std::string pos;
};

class SessionManager {
    public:
        SessionManager() {
            srand(time(nullptr));
        }
        std::string addSession(Session::ptr session) {
            std::string sessionid = std::to_string(rand() + time(nullptr));
            _sessions.insert(std::make_pair(sessionid, session));
            return sessionid;
        }
        Session::ptr getSession(const std::string &sessionid) {
            if(_sessions.find(sessionid) == _sessions.end())
                return nullptr;
            return _sessions[sessionid];
        }
    private:
        std::unordered_map<std::string, Session::ptr> _sessions;
};
